
import { defineStore } from 'pinia'
import { ref } from 'vue'
import settings from '@/config/settings'
import { getUserRouter } from '@/services/user'
import { asyncRouterHandle } from '@/utils/asyncRouter'

export const useRouterStore = defineStore('router', () => {
	var meta = {};
	var asyncRouters = ref([])
	// 从后台获取动态路由
	const LoadRouter = async () => {
		let baseRouter = [{
			title: 'empty',
			path: '/',
			name: 'empty',
			redirect: settings.homeRouteItem.path,
			component: 'layouts/BlankLayout.vue',
			children: []
		},
		
		];
		const response = await getUserRouter();
		baseRouter[0].children = response;
		asyncRouters.value = asyncRouterHandle(baseRouter);
	}
	return {
		asyncRouters,
		LoadRouter,
		meta
	}
})